﻿(function ($) {
    app.modals.CreateOrEditIncomeModal = function () {
        debugger;
        var _billService = abp.services.app.bill;
        var _modalManager;
        var _$form = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$form = _modalManager.getModal().find('form[name=ObjectForm]');
            _$form.validate();
        };
        getCurrentDate();
        this.save = function () {
            if (!_$form.valid()) {
                return;
            }

            var domainObject = _$form.serializeFormToObject();

            _modalManager.setBusy(true);
            _billService.createOrUpdateBill({
                bill: domainObject
            }).done(function (result) {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.setResult(result);
                _modalManager.close();
                abp.event.trigger('app.CreateOrEditModalSaved', result);
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
        $("#SchoolName").val($("#SchoolId").find("option:selected").text())
        $("#IncomeExpendType").val($("#IncomeExpendTypeId").find("option:selected").text())
        $("#BillAccount").val($("#BillAccountId").find("option:selected").text())
        $("#SchoolId").change(function () {
            $("#SchoolName").val($("#SchoolId").find("option:selected").text())
        });
        $("#IncomeExpendTypeId").change(function () {
            $("#IncomeExpendType").val($("#IncomeExpendTypeId").find("option:selected").text())
        });
        $("#BillAccountId").change(function () {
            $("#BillAccount").val($("#BillAccountId").find("option:selected").text())
        });
        $("#CheckProjectId").change(function () {
            $("#CheckProject").val($("#CheckProjectId").find("option:selected").text())
        });
        $("#CheckCustomerId").change(function () {
            $("#CheckCustomer").val($("#CheckCustomerId").find("option:selected").text())
        });
        $("#CheckUserId").change(function () {
            $("#CheckUser").val($("#CheckUserId").find("option:selected").text())
        });
    };
})(jQuery);

//获取当前日期
function getCurrentDate() {
    var currDate = new Date();
    var str = "";
    str = currDate.toLocaleDateString();
    $("#BillDate").val(str);
}